STM8

Compiler Comparison
RTOS Availability

Tutorials

STM8L-DISCOVERY

LED Timer
Serial

STM8S-DISCOVERY

LED Timer
Serial

STM8A-DISCOVERY

STM8AF LED Timer
STM8AF Serial
STM8AF Benchmarks
STM8AL LED Timer
STM8AL Serial

EX-STM8-Q64a-207

LED Timer
Serial
Benchmarks

Open8S208Q80

LED Timer
Serial
Benchmarks

EX-STM8-Q48a-105

LED Timer
Serial

STM8/128-EVAL

LED Timer
Serial
Benchmarks

STM8L101-EVAL

Serial

colecovision.eu

ColecoVision

STM8

MCS-51

LLVM+SDCC

Contact

Getting started with STM8 development using free software: Dhrystone and Whestone on the EX-STM8-Q64a-207

This short tutorial shows how to compile the Dhrystone and Whetstone benchmarks and execute them on a WaveShare EX-STM8-Q64a-207 board, either the premium version (which includes the DVK501) or the standard version with an extra RS232 board. The author used a Debian GNU/Linux system, but the tutorial should work for other Linux distributions, *BSD or other Unices.

The tools we use are

Hardware setup

EX-STM8-Q64a-207 Premium EX-STM8-Q64a-207 Standard with RS232 board

The EX-STM8-Q64a-207 is connected to power via a USB power cable. To write our program to the board, a stlinkv2 is attached. Depending on wether we use the premium version or the standard version with RS232 board, the communication setup is different: For the EX-STM8-Q64a-207 Premium we connect the DVK501 board via the BUS-B connector, which will do for both data and power; the serial cable is then connected to the UART0 header of the DVK50. For the EX-STM8-Q64a-207 Standard with RS232 board, we connect the RS232 board to the PD5 and PD6 headers for data (TxIN to PD5, RxOUT to PD6) and to the power header for power (VCC to +5V, GND to GND); the serial cable is then attached to the RS232 board. On the other end the serial cable is attached to an RS232 port on a computer running a terminal program configured for 9600 baud, no parity, 8 bits, 1 stop bit and no flow control. We used a USB-to-serial converter and gtkterm.

Get SDCC

Depending on your operating system there might be an easy way to install SDCC 3.5.0 or newer using a package system or similar (e.g. apt-get install sdcc on Debian). While SDCC 3.4.0 should be sufficient for this tutorial, you might want to try a newer version in case you encounter any bugs. In particular, SDCC 3.4.0 has an issue with the library search path; this can be worked around by explicitly specifying the path to the standard library when linking.

SDCC binaries or a source tarball can be downloaded from its website.

Get stm8flash

The stm8flash source can be found at its GitHub location, where there is also a download link for a zip archive of the sources. To compile it, a C compiler, such as gcc, pkg-config and libusb need to be installed. Unzip the archive (e.g. using unzip stm8flash-master.zip) change into the directory stm8flash-master and type make. In case there are any errors, such as header files not found, check that pkg-config and development files for libusb are installed.

Get Dhrystone

Download a version of Dhrystone adapted for use with sdcc and the EX-STM8-Q64a-207 board.
Download, and unpack it using tar -xzf dhrystone-stm8s207-uart3-sdcc-3.7.0.tar.gz, change into the directory dhrystone-stm8s207-uart3-sdcc-3.7.0.
You can then compile dhrystone by typing make. In the end there should be a file dhrystone.ihx.

A bit of custom code was necessary to make Dhrystone run using sdcc on the EX-STM8-Q64a-207.See the file dhry.h and portme.c for details. The file portme.c basically combines clock() from the timer demo and putchar() from the serial demo.

Put Dhrystone onto the board

Assuming stm8flash and dhrystone.ihx are in the same directory, the board is attached through an ST-Link/v2 device, ./stm8flash -c stlinkv2 -p stm8s207r8 -w dhrystone.ihx will write Dhrystone onto the board. Dhrystone will run and report its results via USART1. You can see them by attaching a nullmodem cable to the USART1 on the board, and using a terminal program configured for 9600 baud, no parity, 8 bits, 1 stop bit and no flow control. They should look like this (the benchmark numbers may vary depending on the SDCC version used to compile Dhrystone):

Dhrystone Benchmark, Version 2.1 (Language: C)

Program compiled with 'register' attribute

Please give the number of runs through the benchmark: 
Execution starts, 20000 runs through Dhrystone
Execution ends

Final values of the variables used in the benchm     should be:   5
Bool_Glob:           1
        should be:   1
Ch_1_Glob:           A
        should be:   A
Ch_2_Glob:           B
        should be:   B
Arr_1_Glob[8]:       7
        should be:   7
Arr_2_Glob[8][7]:    20010
        should be:   Number_Of_Runs + 10
Ptr_Glob->
  Ptr_Comp:          5131
        should be:   (implementation-dependent)
  Discr:             0
        should be:   0
  Enum_Comp:         2
        should be:   2
  Int_Comp:          17
        should be:   17
  Str_Comp:          DHRYSTONE PROGRAM, SOME STRING
        should be:   DHRYSTONE PROGRAM, SOME STRING
Next_Ptr_Glob->
  Ptr_Comp:          5131
        should be:   (implementation-dependent), same as above
  Discr:             0
        should be:   0
  Enum_Comp:         1
        should be:   1
  Int_Comp:          18
        should be:   18
  Str_Comp:          DHRYSTONE PROGRAM, SOME STRING
        should be:   DHRYSTONE PROGRAM, SOME STRING
Int_1_Loc:           5
        should be:   5
Int_2_Loc:           13
        should be:   13
Int_3_Loc:           7
        should be:   7
Enum_Loc:            1
        should be:   1
Str_1_Loc:           DHRYSTONE PROGRAM, 1'ST STRING
        should be:   DHRYSTONE PROGRAM, 1'ST STRING
Str_2_Loc:           DHRYSTONE PROGRAM, 2'ND STRING
        should be:   DHRYSTONE PROGRAM, 2'ND STRING

Microseconds for one run through Dhrystone: 214 
Dhrystones per Second:                      4658 

Whetstone

Download a version of Whetstone adapted for use with SDCC and the EX-STM8-Q64a-207 board, and proceed as with Dhrystone above. sdcc 3.5.0 does not support double. It replaces double by float and emits a warning to the user. Thus the scores from Whetstone obtained using sdcc 3.5.0 are not really comparable to those from other platforms. Unlike Dhrystone, Whetstone runs the benchmark before doing any text output, so don't worry when it takes some time until something appears on the terminal.

Loops: 10, Iterations: 1, Duration: 17471 msec.
C Converted Double Precision Whetstones: <NO FLOAT> KIPS

Since printf() does not have float support by default, you have to calculate the KIPS score from the data in the first row by hand: Multiply Loops by 100, divide by the duration in seconds. In this case we get a score of 57.2377 KIPS.


More about stm8flash

stm8flash was written by Valentin Dudouyt. It works both with stlink (including the one integrated on the discovery boards) and stlinkv2 devices. The programmer can be selected using -c stlink or -c stlinkv2. The target device is selected using the -p option (to get a list of target devices, use the -p option with an option argument that is not an stm8 device, e.g. -p help. stm8flash will treat filenames ending in .ihx or .hex as Intel hex, and other filenames as binaries.

More about SDCC

SDCC was initially written by Sandeep Dutta for the MCS-51, and has a relatively conservative architecture (see Sandeep Dutta, "Anatomy of a Compiler", 2000). It has been extended by various contributors and more recently, incorporated some cutting-edge technologies, in particular in register allocation (see Philipp Klaus Krause, "Optimal Register Allocation in Polynomial Time", 2013). The stm8 backend was mostly written by Philipp Klaus Krause for his research into bytewise register allocation and spilling (see Philipp Klaus Krause, "Bytewise Register Allocation", 2015).

SDCC is a C compiler that aims to be compliant with the C standards.

Important compiler options for STM8 developers include: